package com.mezz.bones.framework.websocket.handler;

import jakarta.websocket.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 默认的WebSocket消息处理器实现
 */
public class DefaultWebSocketMessageHandler implements WebSocketMessageHandler {
    
    private static final Logger log = LoggerFactory.getLogger(DefaultWebSocketMessageHandler.class);

    @Override
    public void handleMessage(String connectId, String message, Session session) {
        log.info("处理WebSocket消息 - connectId: {}, message: {}", connectId, message);
        
        // 这里添加您的业务逻辑
        // 例如：消息解析、业务处理、响应发送等
        
        try {
            // 示例：简单回显消息
            session.getBasicRemote().sendText("已收到消息: " + message);
        } catch (Exception e) {
            log.error("发送WebSocket响应失败", e);
        }
    }

    @Override
    public String heartBeatData() {
        return "HEARTBEAT:" + new Date().getTime();
    }
}